package Studing;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

/**
 * @ClassName CallableTest
 * @Description: TODO
 * @Author hl
 * @Date 2020/8/1
 * @Version V1.0
 **/
public class CallableTest {




    public static void main(String[] args) {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(20, 500, 10L,
                TimeUnit.SECONDS,new LinkedBlockingQueue<Runnable>(100));




        List<Future<String>> list =new ArrayList<>();
        for(int i=0;i<10;i++){
          list.add(executor.submit(new myCallable()));
        }
        for(int i=0;i<list.size();i++){
            System.out.println(list.get(i).cancel(false));
            try {
                System.out.println(list.get(i).get());
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        }

    }

}
class myRunable implements Runnable{

    @Override
    public void run() {

        System.out.println(Thread.currentThread().getName());
    }
}

class myCallable implements Callable<String>{

    @Override
    public String call() throws Exception {
        return Thread.currentThread().getName();
    }
}
